home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / mac / TIFF / TiffToPS / protos.h < prev    next >
Text File  |  1992-02-21  |  12KB  |  751 lines

  1. /*
  2.  
  3.   protos.h
  4.  
  5.  
  6.  
  7. Original version: Ed McCreight: 30 Oct 90
  8.  
  9. Edit History:
  10.  
  11. Edward Fiala: 10 May 12:59:10 1991
  12.  
  13. Ed McCreight: 10 May 91 11:00
  14.  
  15. End Edit History.
  16.  
  17.  
  18.  
  19. */
  20.  
  21.  
  22.  
  23. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  24.  
  25. *
  26.  
  27. *  This source code is provided to you by Adobe on a non-exclusive,
  28.  
  29. *  royalty-free basis to facilitate your development of PostScript
  30.  
  31. *  language programs.  You may incorporate it into your software as is
  32.  
  33. *  or modified, provided that you include the following copyright
  34.  
  35. *  notice with every copy of your software containing any portion of
  36.  
  37. *  this source code.
  38.  
  39. *
  40.  
  41. * Copyright 1990-1991 Adobe Systems Incorporated.  All Rights Reserved.
  42.  
  43. *
  44.  
  45. * Adobe does not warrant or guarantee that this source code will
  46.  
  47. * perform in any manner.  You alone assume any risks and
  48.  
  49. * responsibilities associated with implementing, using or
  50.  
  51. * incorporating this source code into your software.
  52.  
  53. *
  54.  
  55. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  56.  
  57.  
  58.  
  59. #ifndef    PROTOS_H
  60.  
  61. #define    PROTOS_H
  62.  
  63.  
  64.  
  65.  
  66.  
  67. /* *   F I X E D - L E N G T H   A R G U M E N T   L I S T S   * */
  68.  
  69.  
  70.  
  71. /* The vast majority of C functions accept a fixed number of
  72.  
  73.  * arguments of fixed type.  The macro PROTOTYPES indicates whether
  74.  
  75.  * ANSI function prototypes are to be generated (or else ignored
  76.  
  77.  * as comments) for functions with fixed-length argument lists.
  78.  
  79.  */
  80.  
  81.  
  82.  
  83. #ifndef PROTOTYPES
  84.  
  85. #ifdef __STDC__
  86.  
  87. #define PROTOTYPES    __STDC__
  88.  
  89. #else /* __STDC__ */
  90.  
  91. #define PROTOTYPES    0
  92.  
  93. #endif /* __STDC__ */
  94.  
  95. #endif /* PROTOTYPES */
  96.  
  97.  
  98.  
  99. /* The function prototype macros ARGDECLn() and
  100.  
  101.  * ARGDEFn() should be as in the following example.
  102.  
  103.  * The n refers to the (fixed) number of arguments.
  104.  
  105.  */
  106.  
  107.  
  108.  
  109. #if 0 /* * *   B e g i n   c o m m e n t   * * */
  110.  
  111.  
  112.  
  113. /* ... in interface foozle.h: */
  114.  
  115. extern procedure foo ARGDECL2(integer, arg1, char *, arg2);
  116.  
  117.  
  118.  
  119.   /* Note: If PROTOTYPES is true, the above expands to
  120.  
  121.    *
  122.  
  123.    *    extern procedure foo (integer arg1, char * arg2);
  124.  
  125.    *     
  126.  
  127.    * if not, it expands to
  128.  
  129.    *
  130.  
  131.    *    extern procedure foo ();
  132.  
  133.    *
  134.  
  135.    * Note also that the first argument could optionally have
  136.  
  137.    * been typed as "register integer" instead of "integer".
  138.  
  139.    * The adjective "register" has no effect in a function
  140.  
  141.    * declaration.
  142.  
  143.    */
  144.  
  145.  
  146.  
  147.  
  148.  
  149. /* ... in implementation foozle.c: */
  150.  
  151.  # include "foozle.h"
  152.  
  153.  
  154.  
  155.  public procedure foo ARGDEF2(register integer, arg1, char *, arg2)
  156.  
  157.  
  158.  
  159.   /* Note: If PROTOTYPES is true, the above expands to
  160.  
  161.    *
  162.  
  163.    *    public procedure foo (register integer arg1, char * arg2)
  164.  
  165.    *
  166.  
  167.    * if not, it expands to
  168.  
  169.    *
  170.  
  171.    *    public procedure foo (arg1, arg2)
  172.  
  173.    *    register integer arg1;
  174.  
  175.    *    char * arg2;
  176.  
  177.    */
  178.  
  179.    
  180.  
  181. {
  182.  
  183.   /* statements of procedure foo */
  184.  
  185. }
  186.  
  187.  
  188.  
  189. /* .. in client in baz.c */
  190.  
  191.  # include "foozle.h"
  192.  
  193.  
  194.  
  195.  foo(3, "abc");
  196.  
  197.  
  198.  
  199. #endif /* * *   E n d   c o m m e n t   * * */
  200.  
  201.  
  202.  
  203. /* In a non-ANSI system, prototypes are good documentation.
  204.  
  205.  * They also help ANSI compilers catch type-mismatch errors.
  206.  
  207.  *
  208.  
  209.  * Portability warning:  Prototypes alter the rules for function argument
  210.  
  211.  * type conversions.  Be sure that all references
  212.  
  213.  * to prototype-defined functions are in the scope of prototype
  214.  
  215.  * declarations, and that any function that is prototype-declared
  216.  
  217.  * is also prototype-defined.  The latter can be checked by the compiler,
  218.  
  219.  * but the former generally cannot.  Since a prototyped definition
  220.  
  221.  * serve as a prototyped declaration, a private function does not
  222.  
  223.  * need a separate declaration if its definition textually precedes
  224.  
  225.  * its first use.  This definition-before-use order is natural to
  226.  
  227.  * Pascal programmers.
  228.  
  229.  */
  230.  
  231.  
  232.  
  233. #if PROTOTYPES
  234.  
  235.  
  236.  
  237. #define ARGDEF0()                            \
  238.  
  239.   (void)
  240.  
  241. #define ARGDEF1(t1,v1)                            \
  242.  
  243.   (t1 v1)
  244.  
  245. #define ARGDEF2(t1,v1,t2,v2)                        \
  246.  
  247.   (t1 v1,t2 v2)
  248.  
  249. #define ARGDEF3(t1,v1,t2,v2,t3,v3)                    \
  250.  
  251.   (t1 v1,t2 v2,t3 v3)
  252.  
  253. #define ARGDEF4(t1,v1,t2,v2,t3,v3,t4,v4)                \
  254.  
  255.   (t1 v1,t2 v2,t3 v3,t4 v4)
  256.  
  257. #define ARGDEF5(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5)                \
  258.  
  259.   (t1 v1,t2 v2,t3 v3,t4 v4,t5 v5)
  260.  
  261. #define ARGDEF6(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6)            \
  262.  
  263.   (t1 v1,t2 v2,t3 v3,t4 v4,t5 v5,t6 v6)
  264.  
  265. #define ARGDEF7(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7)        \
  266.  
  267.   (t1 v1,t2 v2,t3 v3,t4 v4,t5 v5,t6 v6,t7 v7)
  268.  
  269. #define ARGDEF8(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7,t8,v8)    \
  270.  
  271.   (t1 v1,t2 v2,t3 v3,t4 v4,t5 v5,t6 v6,t7 v7,t8 v8)
  272.  
  273. #define ARGDEF9(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7,t8,v8,t9,v9)    \
  274.  
  275.   (t1 v1,t2 v2,t3 v3,t4 v4,t5 v5,t6 v6,t7 v7,t8 v8,t9 v9)
  276.  
  277. #define ARGDEF10(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7,t8,v8,t9,v9,t10,v10) \
  278.  
  279.   (t1 v1,t2 v2,t3 v3,t4 v4,t5 v5,t6 v6,t7 v7,t8 v8,t9 v9,t10 v10)
  280.  
  281.  
  282.  
  283. #define ARGDECL0    ARGDEF0
  284.  
  285. #define ARGDECL1    ARGDEF1
  286.  
  287. #define ARGDECL2    ARGDEF2
  288.  
  289. #define ARGDECL3    ARGDEF3
  290.  
  291. #define ARGDECL4    ARGDEF4
  292.  
  293. #define ARGDECL5    ARGDEF5
  294.  
  295. #define ARGDECL6    ARGDEF6
  296.  
  297. #define ARGDECL7    ARGDEF7
  298.  
  299. #define ARGDECL8    ARGDEF8
  300.  
  301. #define ARGDECL9    ARGDEF9
  302.  
  303.  
  304.  
  305. #else /* PROTOTYPES */
  306.  
  307.  
  308.  
  309. #define ARGDEF0()                            \
  310.  
  311.   ()
  312.  
  313. #define ARGDEF1(t1,v1)                            \
  314.  
  315.   (v1) t1 v1;
  316.  
  317. #define ARGDEF2(t1,v1,t2,v2)                        \
  318.  
  319.   (v1,v2) t1 v1; t2 v2;
  320.  
  321. #define ARGDEF3(t1,v1,t2,v2,t3,v3)                    \
  322.  
  323.   (v1,v2,v3) t1 v1; t2 v2; t3 v3;
  324.  
  325. #define ARGDEF4(t1,v1,t2,v2,t3,v3,t4,v4)                \
  326.  
  327.   (v1,v2,v3,v4) t1 v1; t2 v2; t3 v3; t4 v4;
  328.  
  329. #define ARGDEF5(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5)                \
  330.  
  331.   (v1,v2,v3,v4,v5) t1 v1; t2 v2; t3 v3; t4 v4; t5 v5;
  332.  
  333. #define ARGDEF6(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6)            \
  334.  
  335.   (v1,v2,v3,v4,v5,v6) t1 v1; t2 v2; t3 v3; t4 v4; t5 v5; t6 v6;
  336.  
  337. #define ARGDEF7(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7)        \
  338.  
  339.   (v1,v2,v3,v4,v5,v6,v7)                        \
  340.  
  341.   t1 v1; t2 v2; t3 v3; t4 v4; t5 v5; t6 v6; t7 v7;
  342.  
  343. #define ARGDEF8(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7,t8,v8)    \
  344.  
  345.   (v1,v2,v3,v4,v5,v6,v7,v8)                        \
  346.  
  347.   t1 v1; t2 v2; t3 v3; t4 v4; t5 v5; t6 v6; t7 v7; t8 v8;
  348.  
  349. #define ARGDEF9(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7,t8,v8,t9,v9)    \
  350.  
  351.   (v1,v2,v3,v4,v5,v6,v7,v8,v9)                        \
  352.  
  353.   t1 v1; t2 v2; t3 v3; t4 v4; t5 v5; t6 v6; t7 v7; t8 v8; t9 v9;
  354.  
  355. #define ARGDEF10(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7,t8,v8,t9,v9,t10,v10) \
  356.  
  357.   (v1,v2,v3,v4,v5,v6,v7,v8,v9,v10)                    \
  358.  
  359.   t1 v1; t2 v2; t3 v3; t4 v4; t5 v5; t6 v6; t7 v7; t8 v8; t9 v9; t10 v10;
  360.  
  361.  
  362.  
  363.  
  364.  
  365. #define ARGDECL0()                            \
  366.  
  367.   ()
  368.  
  369. #define ARGDECL1(t1,v1)                            \
  370.  
  371.   ()
  372.  
  373. #define ARGDECL2(t1,v1,t2,v2)                        \
  374.  
  375.   ()
  376.  
  377. #define ARGDECL3(t1,v1,t2,v2,t3,v3)                    \
  378.  
  379.   ()
  380.  
  381. #define ARGDECL4(t1,v1,t2,v2,t3,v3,t4,v4)                \
  382.  
  383.   ()
  384.  
  385. #define ARGDECL5(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5)                \
  386.  
  387.   ()
  388.  
  389. #define ARGDECL6(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6)            \
  390.  
  391.   ()
  392.  
  393. #define ARGDECL7(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7)        \
  394.  
  395.   ()
  396.  
  397. #define ARGDECL8(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7,t8,v8)    \
  398.  
  399.   ()
  400.  
  401. #define ARGDECL9(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7,t8,v8,t9,v9)    \
  402.  
  403.   ()
  404.  
  405. #define ARGDECL10(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7,t8,v8,t9,v9,t10,v10) \
  406.  
  407.   ()
  408.  
  409.  
  410.  
  411. #endif /* PROTOTYPES */
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419. /* *   V A R I A B L E - L E N G T H   A R G U M E N T   L I S T S   * */
  420.  
  421.  
  422.  
  423. /* A small but interesting minority of C functions accepts
  424.  
  425.  * a variable number of arguments of variable type.  The
  426.  
  427.  * most widely known such function is printf().  There are
  428.  
  429.  * two commonly-accepted mechanisms for declaring and defining
  430.  
  431.  * such functions and sequencing through the arguments.
  432.  
  433.  *
  434.  
  435.  * The ANSI mechanism declares such a function to have a
  436.  
  437.  * fixed number of fixed-type arguments (at least one), followed
  438.  
  439.  * by an indeterminate number of arguments of unspecified type.
  440.  
  441.  * The indeterminate arguments are indicated by an ellipsis (...).
  442.  
  443.  * A set of macros for sequencing through the indeterminate
  444.  
  445.  * arguments is contained in the header file <stdarg.h>.
  446.  
  447.  *
  448.  
  449.  * The pre-ANSI mechanism declares such a function to have
  450.  
  451.  * no declared arguments ().  A set of macros for sequencing
  452.  
  453.  * through all the arguments is contained in the header file
  454.  
  455.  * <varargs.h>.
  456.  
  457.  *
  458.  
  459.  * Every C compiler should support one mechanism or the
  460.  
  461.  * other, and some support both.
  462.  
  463.  *
  464.  
  465.  * + The macro USE_STDARG selects which mechanism will be used.
  466.  
  467.  * + The macro PS_stdarg names the header file that defines the
  468.  
  469.  *     macros to be used for sequencing through variable-length
  470.  
  471.  *     argument lists.  Its name avoids using all capital letters,
  472.  
  473.  *     to prevent the makefile autobuilder from trying to read it.
  474.  
  475.  * + The macro PROTOTYPES_V indicates whether
  476.  
  477.  *     ANSI function prototypes are to be generated (or else ignored
  478.  
  479.  *     as comments) for functions with variable-length argument lists.
  480.  
  481.  *
  482.  
  483.  * In almost all cases, these macros should default correctly from
  484.  
  485.  * ANSI_C, but USE_STDARG allows the possibility of a future exception.
  486.  
  487.  */
  488.  
  489.  
  490.  
  491. #ifndef USE_STDARG
  492.  
  493. #define USE_STDARG    ANSI_C
  494.  
  495. #endif
  496.  
  497.  
  498.  
  499. #ifndef PS_stdarg
  500.  
  501. #if USE_STDARG
  502.  
  503. #define PS_stdarg    <stdarg.h>
  504.  
  505. #else /* !USE_STDARG */
  506.  
  507. #define PS_stdarg    <varargs.h>
  508.  
  509. #endif /* USE_STDARG */
  510.  
  511. #endif /* ndef PS_stdarg */
  512.  
  513.  
  514.  
  515. #ifndef PROTOTYPES_V
  516.  
  517. #define PROTOTYPES_V    USE_STDARG
  518.  
  519. #endif
  520.  
  521.  
  522.  
  523. /*
  524.  
  525.  * Here is an example using variable-length argument lists.
  526.  
  527.  * The function foovsum takes k+1 arguments: the first, k, tells
  528.  
  529.  * how many others there are, and the remaining ones are reals.
  530.  
  531.  * The function foovsum returns the sum of the last k arguments.
  532.  
  533.  *
  534.  
  535.  * Within the body of foovsum, argp is a local variable defined by
  536.  
  537.  * the macro ARGDEFVn().  Its type is va_list, defined
  538.  
  539.  * by stdarg.h or varargs.h.  argp points in a compiler-dependent way
  540.  
  541.  * to the still-unconsumed part of the argument list.  va_arg(p, t)
  542.  
  543.  * is a macro defined by stdarg.h or varargs.h that
  544.  
  545.  * returns the next argument (which must be of type t) from the
  546.  
  547.  * still-unconsumed part of the argument list pointed to by p,
  548.  
  549.  * and consumes it by advancing p.
  550.  
  551.  */
  552.  
  553.  
  554.  
  555. #if 0 /* * *   B e g i n   c o m m e n t   * * */
  556.  
  557.  
  558.  
  559. /* ... in interface foozle.h: */
  560.  
  561.   real foovsum ARGDECLV1(int, k);
  562.  
  563.  
  564.  
  565. /* ... in implementation foozle.c: */
  566.  
  567.  #include PS_stdarg
  568.  
  569.  #include "foozle.h"
  570.  
  571.  
  572.  
  573.  real foovsum ARGDEFV1(int, k)
  574.  
  575.  {
  576.  
  577.    int i;
  578.  
  579.    real sum = 0.0;
  580.  
  581.    for (i = 0; i < k; i++)
  582.  
  583.     sum += va_arg(argp, real);
  584.  
  585.    return sum;
  586.  
  587.  }
  588.  
  589.  ARGDEFV_END
  590.  
  591.  
  592.  
  593. /* ... in sources/makefile for foozle.c: */
  594.  
  595.  # AUTOIGNORE = (PS_stdarg)
  596.  
  597.  
  598.  
  599. /* ... in client baz.c: */
  600.  
  601.  #include "foozle.h"
  602.  
  603.  real sum = foovsum(3, 1.0, 2.0, 3.0); /* sum == 6.0 */
  604.  
  605.  
  606.  
  607. #endif  /* 0 * *   E n d   c o m m e n t   * * */
  608.  
  609.  
  610.  
  611.  
  612.  
  613. #if PROTOTYPES_V
  614.  
  615.  
  616.  
  617. #define ARGDECLV1(t1,v1)                        \
  618.  
  619.   (t1 v1,...)
  620.  
  621. #define ARGDECLV2(t1,v1,t2,v2)                        \
  622.  
  623.   (t1 v1,t2 v2,...)
  624.  
  625. #define ARGDECLV3(t1,v1,t2,v2,t3,v3)                    \
  626.  
  627.   (t1 v1,t2 v2,t3 v3,...)
  628.  
  629. #define ARGDECLV4(t1,v1,t2,v2,t3,v3,t4,v4)                \
  630.  
  631.   (t1 v1,t2 v2,t3 v3,t4 v4,...)
  632.  
  633.  
  634.  
  635. #else /* !PROTOTYPES_V */
  636.  
  637.  
  638.  
  639. #define ARGDECLV1(t1,v1)                        \
  640.  
  641.   ()
  642.  
  643. #define ARGDECLV2(t1,v1,t2,v2)                        \
  644.  
  645.   ()
  646.  
  647. #define ARGDECLV3(t1,v1,t2,v2,t3,v3)                    \
  648.  
  649.   ()
  650.  
  651. #define ARGDECLV4(t1,v1,t2,v2,t3,v3,t4,v4)                \
  652.  
  653.   ()
  654.  
  655.  
  656.  
  657. #endif /* PROTOTYPES_V */
  658.  
  659.  
  660.  
  661. #if USE_STDARG
  662.  
  663.  
  664.  
  665. #define ARGDEFV1(t1,v1)                            \
  666.  
  667.   (t1 v1,...) { va_list argp; va_start(argp, v1);
  668.  
  669. #define ARGDEFV2(t1,v1,t2,v2)                        \
  670.  
  671.   (t1 v1,t2 v2,...) { va_list argp; va_start(argp, v2);
  672.  
  673. #define ARGDEFV3(t1,v1,t2,v2,t3,v3)                    \
  674.  
  675.   (t1 v1,t2 v2,t3 v3,...) { va_list argp; va_start(argp, v3);
  676.  
  677. #define ARGDEFV4(t1,v1,t2,v2,t3,v3,t4,v4)                \
  678.  
  679.   (t1 v1,t2 v2,t3 v3,t4 v4,...) { va_list argp; va_start(argp, v4);
  680.  
  681.  
  682.  
  683. #else /* !USE_STDARG */
  684.  
  685.  
  686.  
  687. #define ARGDEFV1(t1,v1)                            \
  688.  
  689.   (va_alist) va_dcl {                            \
  690.  
  691.   va_list argp; t1 v1;                            \
  692.  
  693.   va_start(argp);                            \
  694.  
  695.   v1 = va_arg(argp, t1);
  696.  
  697. #define ARGDEFV2(t1,v1,t2,v2)                        \
  698.  
  699.   (va_alist) va_dcl {                            \
  700.  
  701.   va_list argp; t1 v1; t2 v2;                        \
  702.  
  703.   va_start(argp);                            \
  704.  
  705.   v1 = va_arg(argp, t1);                        \
  706.  
  707.   v2 = va_arg(argp, t2);
  708.  
  709. #define ARGDEFV3(t1,v1,t2,v2,t3,v3)                    \
  710.  
  711.   (va_alist) va_dcl {                            \
  712.  
  713.   va_list argp; t1 v1; t2 v2; t3 v3;                    \
  714.  
  715.   va_start(argp);                            \
  716.  
  717.   v1 = va_arg(argp, t1);                        \
  718.  
  719.   v2 = va_arg(argp, t2);                        \
  720.  
  721.   v3 = va_arg(argp, t3);
  722.  
  723. #define ARGDEFV4(t1,v1,t2,v2,t3,v3,t4,v4)                    \
  724.  
  725.   (va_alist) va_dcl {                            \
  726.  
  727.   va_list argp; t1 v1; t2 v2; t3 v3; t4 v4;                \
  728.  
  729.   va_start(argp);                            \
  730.  
  731.   v1 = va_arg(argp, t1);                        \
  732.  
  733.   v2 = va_arg(argp, t2);                        \
  734.  
  735.   v3 = va_arg(argp, t3);                        \
  736.  
  737.   v4 = va_arg(argp, t4);
  738.  
  739.  
  740.  
  741. #endif /* USE_STDARG */
  742.  
  743.  
  744.  
  745. #define ARGDEFV_END    }
  746.  
  747.  
  748.  
  749. #endif    /* PROTOS_H */
  750.  
  751.